import request from '@/utils/request'

const spuRules ={

  productId: [
    { required: true, message: '请选输入产品id', trigger: 'blur' },
    { validator: (rule, value, callback) => {
        if (value) {
          if (/[\u4E00-\u9FA5]/g.test(value)) {
            callback(new Error("不能输入汉字"));
          } else if (/\s/g.test(value)) {
            callback(new Error("不能有空格"));
          } else {
            request({
              url: '/admin/product/isExist',
              method: 'GET',
              params : { productId: value }
            }).then(res => {
              if (res.state === true){
                callback();
              }else {
                callback(new Error(res.message));
              }
            })
          }
        }
      }, trigger: 'blur' },
  ],
  categoryAndBrand: [
    { required: true, message: '请选类别和品牌', trigger: 'change' }
  ],
  name: [
    { required: true, message: '请输入产品名称', trigger: 'blur' },
    { min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur' }
  ],
  title: [
    { required: true, message: '请输入产品标题', trigger: 'blur' }
  ],
  describe: [
    { required: true, message: '请输入产品描述', trigger: 'blur' }
  ],
  detail: [
    { required: true, message: '请输入产品详情', trigger: 'blur' }
  ],
}

const skuRules ={
  productId: [
    { required: true, message: '产品ID不能为空', trigger: 'blur' }
  ],
  title: [
    { required: true, message: '请输入产品标题', trigger: 'blur' }
  ],
  specsID: [
    { required: true, message: '规格ID不能为空', trigger: 'blur' }
  ],
  productSpecs: [
    { required: true, message: '规格信息不能为空', trigger: 'blur' }
  ],
  price: [
    { required: true, message: '价格不能为空', trigger: 'blur' }
  ],
  specsStock: [
    { required: true, message: '规格库存不能为空', trigger: 'blur' }
  ],
  state: [
    { required: true, message: '状态不能为空', trigger: 'blur' }
  ]
}
export { spuRules,skuRules }
